package com.core.zyyz.pcmc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.core.common.utils.poi.ExcelUtil;
import com.core.zyyz.pcmc.domain.PcmcHomeTemplate;
import com.core.zyyz.pcmc.service.PcmcHomeTemplateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.common.core.page.TableDataInfo;

/**
 * 首页模板Controller
 *
 * @author core
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/pcmc/template")
public class PcmcHomeTemplateController extends BaseController
{
    @Autowired
    private PcmcHomeTemplateService pcmcHomeTemplateService;

    /**
     * 查询首页模板列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcHomeTemplate pcmcHomeTemplate)
    {
        startPage();
        List<PcmcHomeTemplate> list = pcmcHomeTemplateService.selectPcmcHomeTemplateList(pcmcHomeTemplate);
        return getDataTable(list);
    }

    /**
     * 获取首页模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:template:query')")
    @GetMapping(value = "/{templateCode}")
    public AjaxResult getInfo(@PathVariable("templateCode") String templateCode)
    {
        return success(pcmcHomeTemplateService.selectPcmcHomeTemplateByTemplateCode(templateCode));
    }

    /**
     * 新增首页模板
     */
    @PreAuthorize("@ss.hasPermi('pcmc:template:add')")
    @Log(title = "首页模板", businessType = BusinessType.INSERT)
    @PostMapping("/insertTemplate")
    public AjaxResult add(@RequestBody PcmcHomeTemplate pcmcHomeTemplate)
    {
        return toAjax(pcmcHomeTemplateService.insertPcmcHomeTemplate(pcmcHomeTemplate));
    }

    /**
     * 修改首页模板
     */
    @PreAuthorize("@ss.hasPermi('pcmc:template:edit')")
    @Log(title = "首页模板", businessType = BusinessType.UPDATE)
    @PostMapping("/updateTemplate")
    public AjaxResult edit(@RequestBody PcmcHomeTemplate pcmcHomeTemplate)
    {
        return toAjax(pcmcHomeTemplateService.updatePcmcHomeTemplate(pcmcHomeTemplate));
    }

    /**
     * 删除首页模板
     */
    @PreAuthorize("@ss.hasPermi('pcmc:template:remove')")
    @Log(title = "首页模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{templateCodes}")
    public AjaxResult remove(@PathVariable String[] templateCodes)
    {
        return toAjax(pcmcHomeTemplateService.deletePcmcHomeTemplateByTemplateCodes(templateCodes));
    }
}
